#include"comm.h"

int main()
{
    key_t key = ftok(PATHNAME, PROJ_ID);
    if(key < 0)
    {
        perror("ftok fail!");
        return 1;
    }

    int shm = shmget(key, SIZE, IPC_CREAT | IPC_EXCL | 0666);
    if(shm < 0)
    {
        perror("shmget fail!");
        return 2;
    }

    printf("key: %x\n", key); 
    printf("shm: %d\n", shm);

    // sleep(2);
    // shmctl(shm, IPC_RMID, NULL);
    // sleep(2);

    //cout << "attach begin!" << endl;
    //共享内存关联
    char* mem = (char*)shmat(shm, NULL, 0);
    if(mem == (void*)-1)
    {
        perror("shmat fail!");
        return 3;
    }

    //cout << "attach end!" << endl;

    //cout << "detach begin!" << endl;
    //sleep(2);
    while(1)
    {

    }
    //共享内存去关联;
    shmdt(mem);
    //cout << "detach end!" << endl;

    //shmctl(shm, IPC_RMID, NULL);
    return 0;
}